#include <bits/stdc++.h>
using namespace std;
#define int long long 

int n, C, dp[2][1000006], a[1000006];
vector<int> ls;
signed main() {
	freopen("minimize.in", "r", stdin); freopen("minimize.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> C;
	if (C == 0) {
		cout << "0\n";
		return 0;
	}
	bool flg = 1;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		flg &= (a[i] >= a[i - 1]);
		ls.push_back(a[i]);
	}
	sort(ls.begin(), ls.end());
	ls.erase(unique(ls.begin(), ls.end()), ls.end());
	int m = ls.size();
	if (n * m <= 3e7) {
		for (int i = n; i >= 1; --i) {
			for (int j = 1; j <= m; ++j) {
				if (j != 1) dp[i & 1][j] = dp[i & 1][j - 1];
				else dp[i & 1][j] = 1ll << 60;
				dp[i & 1][j] = min(dp[i & 1][j], dp[(i + 1) & 1][j] + (ls[j - 1] >= a[i] ? ls[j - 1] - a[i] : C));
			}
		}
		cout << dp[1][m] << "\n";
	} else if (flg) {
		int sum = 0, ans = 1ll << 60;
		for (int i = 1; i <= n; ++i) {
			sum += a[i];
			ans = min(ans, a[i] * i - sum + (n - i) * C);
		}
		cout << ans << "\n";
	}
	return 0;
}
